<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>判断数组是否包含某对象</title>
</head>

<body>

</body>
<script>
  "use strict"; {
    let data = [
      { name: '浪里行舟' },
      { name: '前端工匠' },
      { name: '前端开发' },
    ];
    let val = { name: '浪里行舟' };
    console.log(~JSON.stringify(data).indexOf(JSON.stringify(val)));//true
    if (~JSON.stringify(data).indexOf(JSON.stringify(val))) {
      console.log(true);
    } else {
      console.log(false);
    };
  }; {
    let obj1 = {
      a: 1,
      b: 2
    }, obj2 = {
      a: 1,
      b: 2,
    };
    // 对象如果调整了键的顺序，就会判断出错！
    console.log(JSON.stringify(obj1) === JSON.stringify(obj2)) // true
  };
</script>

</html>